import request from "../request";

// 订单详情类型
export interface OrderDetail {
  id: string;
  orderNo: string;
  userId: string;
  orderType: number; // 0线上碎片//1线下预约/2排班/3处方
  amount: number;    // 金额
  status: number;    // 0为未支付
  payDeadline: string;
  createdAt: string;
}

// 获取订单详情响应类型
interface GetOrderResponse {
  code: number;
  msg?: string;
  data: OrderDetail;
}

// 支付请求参数类型
export interface PayOrderRequest {
  id: string | number;        // 订单id
  patientId: number;          // 患者id
  staffId: number;            // 医生id
  typeId: number;             // 1为线下
  amount: number;             // 金额
  payDeadline: string;        // 订单超时时间
  userId: number;             // 用户id
}

// 支付响应类型
interface PayOrderResponse {
  code: number;
  msg?: string;
}

// 获取订单详情（预约挂号 typeId 固定为 0）
export const getOrder = async (orderId: string, typeId = 0): Promise<GetOrderResponse> => {
  const data = await request({
    url: `/order/getOrder/${orderId}/${typeId}`,
    method: "GET"
  });
  return data;
};

// 支付订单
export const payOrder = async (params: PayOrderRequest): Promise<PayOrderResponse> => {
  const data = await request({
    url: "/order/pay",
    method: "POST",
    data: params
  });
  return data;
};
